<?php
/*
//	
//	author: dvquan
//	version: 1.00.01
//	updated: 18/08/2010
*/
class LevelStudyKit extends BaseLevelStudyKit
{
	public function delete(PropelPDO $con = null)
   {
    	parent::delete($con);
		
		if(file_exists(sfConfig::get('sf_upload_dir').'/assets/levelstudykit/'.utilities::getSpreadPathByDate($this->getCreatedAt()).'/'.$this->getLskImage())) {
    		unlink(sfConfig::get('sf_upload_dir').'/assets/levelstudykit/'.utilities::getSpreadPathByDate($this->getCreatedAt()).'/'.$this->getLskImage());
			unlink(sfConfig::get('sf_upload_dir').'/assets/levelstudykit/'.utilities::getSpreadPathByDate($this->getCreatedAt()).'/thumb_'.$this->getLskImage());
			//$datetime = date_create($this->getCreatedAt());
			//$pathDelete = sfConfig::get('sf_upload_dir').'/assets/news/'.date_format($datetime, 'Y/m');
			//utilities::deleteAll($pathDelete, true);
		}
				
   }
   // udp 18.08.2010 xu ly set status = 0 when status is null
   	public function save(PropelPDO $con = null) 
	{
		//sfContext::createInstance($this->configuration);
		$status = $this->getLskStatus();
		if( !isset($status) )
			$this->setLskStatus(0);
		//$response = sfContext::getInstance()->getResponse();  	
		$con->beginTransaction();
		try
		{
			$res = parent::save($con);
			$con->commit();
			return $res;
		} catch (Exception $e) {
			$con->rollBack();
			throw $e;
		}
	}

}
